package com.tadpole.music.view.activity.me;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.tadpole.music.R;
import com.tadpole.music.adapter.me.MyPointsAdapter;
import com.tadpole.music.adapter.me.MyStudentAdapter;
import com.tadpole.music.bean.me.MyPointListBean;
import com.tadpole.music.iView.me.MyPointListIView;
import com.tadpole.music.presenter.me.MyPointListPresenter;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.view.activity.base.BaseActivity;

import java.util.List;


/**
 * 我的积分
 * Created By 孙岩
 * on 2021/1/10
 */
public class MyPointsActivity extends BaseActivity implements MyPointListIView {
    //回退
    private View view_back_icon;
    //积分说明
    private TextView right_icon_text;
    //标题
    private TextView actionbar_title;
    //积分
    private TextView tvJiFenCount;
    //刷新加载
    private SmartRefreshLayout rl_refresh;
    //积分记录recyclerView
    private RecyclerView recyclerView;
    //积分记录adapter
    private MyPointsAdapter myPointsAdapter;
    //积分记录
    private MyPointListPresenter myPointListPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_points);
        initViews();
        initListeners();

        myPointListPresenter = new MyPointListPresenter();
        myPointListPresenter.attachView(this);
        myPointListPresenter.getMyPointList();
    }

    //初始化控件
    @SuppressLint("SetTextI18n")
    private void initViews(){
        view_back_icon = findViewById(R.id.view_back_icon);
        right_icon_text = findViewById(R.id.right_icon_text);
        right_icon_text.setVisibility(View.VISIBLE);
        right_icon_text.setText("积分说明");
        actionbar_title = findViewById(R.id.actionbar_title);
        actionbar_title.setText("我的积分");
        tvJiFenCount = findViewById(R.id.tvJiFenCount);
        rl_refresh = findViewById(R.id.rl_refresh);
        rl_refresh.setEnableRefresh(false);
        rl_refresh = findViewById(R.id.rl_refresh);
        recyclerView = findViewById(R.id.recyclerView);

        tvJiFenCount.setText(getIntent().getIntExtra("point",0)+"");
    }

    //初始化监听器
    private void initListeners(){
        view_back_icon.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                MyPointsActivity.this.finish();
            }
        });

        //加载
        rl_refresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                myPointListPresenter.getMyPointListMore();
            }
        });

        //积分说明
        right_icon_text.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                Intent intent = new Intent(MyPointsActivity.this,PointsExplainActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void notifyAdapter() {
        myPointsAdapter.notifyDataSetChanged();
    }

    @Override
    public void stopRefresh() {
        rl_refresh.finishLoadMore();
    }

    @Override
    public void showPointList(List<MyPointListBean.DataBeanX.DataBean> list) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        //创建适配器
        myPointsAdapter = new MyPointsAdapter(this,list);
        //给RecyclerView设置适配器
        recyclerView.setAdapter(myPointsAdapter);
        recyclerView.setNestedScrollingEnabled(false);
    }
}
